package problems

class EulersSolutions {
	
	List numberList =  []
	List fibunacciNumbers = []
	
	EulersSolutions() {
		for(x in 1..999) {
			if(x % 3 == 0 || x % 5 == 0)
				numberList.add(x)
		}
		generateFibunacciNumbersUpTo4MillionWithSequence(1, 2)
		
	}

	def getNumbersBelow(Integer value) {
		def list = []
		numberList.each { x ->
			if(x < value)
				list.add(x)
		}
		list
	}
	
	void generateFibunacciNumbersUpTo4MillionWithSequence(int number1, int number2) {
		fibunacciNumbers.clear()
		def x = number2
		fibunacciNumbers.add(number1)
		fibunacciNumbers.add(number2)
		while ( x < 4000000) {
			x = number1 + number2
			if(x < 4000000) {
				fibunacciNumbers.add(x)
				number1 = number2
				number2 = x
			}
		}
	}
	
	def biggestPrime(def value) {
		return primeNumbers(value).last()
	}
	
	def isPrime(def value) {
		def primes = []
		for(def x = 2; x <= value; x++) {
			if(value % x == 0 && x != value) {
				return false
			}
		}
		return true
	}
	
	def primeNumbers(def value) {
		def primes = []
		for(def x = 2; x <= value; x++) {
			if(value % x == 0) {
				if(isPrime(x))
					primes.add(x)
					value = (Long)value / x
			}
		}
		return primes
	}
	
	
}
